package frame.options.virtual.create;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentListener;

import model.components.networks.virtual.VirtualNetworks;

@SuppressWarnings("serial")
public class CreateVirtualSelectPanel extends JPanel 
{
	private JLabel networksNumberLabel;
	public JLabel getNetworksNumberLabel(){ return networksNumberLabel; }
	public void setNetworksNumberLabel( JLabel networksNumberLabel ){ this.networksNumberLabel = networksNumberLabel; }
	
	private JTextField networksNumberTextField;
	public JTextField getNetworksNumberTextField(){ return networksNumberTextField; }
	public void setNetworksNumberTextField( JTextField networksNumberTextField ){ this.networksNumberTextField = networksNumberTextField; }

	private JLabel windowTimeUnitsNumberLabel;
    public JLabel getWindowTimeUnitsNumberLabel(){ return windowTimeUnitsNumberLabel; }
	public void setWindowTimeUnitsNumberLabel( JLabel windowTimeUnitsNumberLabel ){ this.windowTimeUnitsNumberLabel = windowTimeUnitsNumberLabel; }
	
	private JTextField windowTimeUnitsNumberTextField;
    public JTextField getWindowTimeUnitsNumberTextField(){ return windowTimeUnitsNumberTextField; }
	public void setWindowTimeUnitsNumberTextField( JTextField windowTimeUnitsNumberTextField ){ this.windowTimeUnitsNumberTextField = windowTimeUnitsNumberTextField; }

	private JLabel poissonArrivesLabel;
    public JLabel getPoissonArrivesLabel(){ return poissonArrivesLabel; }
	public void setPoissonArrivesLabel( JLabel poissonArrivesLabel ){ this.poissonArrivesLabel = poissonArrivesLabel; }
	
	private JTextField poissonArrivesTextField;
    public JTextField getPoissonArrivesTextField(){ return poissonArrivesTextField; }
	public void setPoissonArrivesTextField( JTextField poissonArrivesTextField ){ this.poissonArrivesTextField = poissonArrivesTextField; }

	private JLabel exponentialLifetimeLabel;
    public JLabel getExponentialLifetimeLabel(){ return exponentialLifetimeLabel; }
	public void setExponentialLifetimeLabel( JLabel exponentialLifetimeLabel ){ this.exponentialLifetimeLabel = exponentialLifetimeLabel; }
	
	private JTextField exponentialLifetimeTextField;
    public JTextField getExponentialLifetimeTextField(){ return exponentialLifetimeTextField; }
	public void setExponentialLifetimeTextField( JTextField exponentialLifetimeTextField ){ this.exponentialLifetimeTextField = exponentialLifetimeTextField; }

	private JLabel routersNumberLabel;
	public JLabel getRoutersNumberLabel(){ return routersNumberLabel; }
	public void setRoutersNumberLabel( JLabel routersNumberLabel ){ this.routersNumberLabel = routersNumberLabel; }
	
	private JTextField minRoutersNumberTextField;
	public JTextField getMinRoutersNumberTextField(){ return minRoutersNumberTextField; }
	public void setMinRoutersNumberTextField( JTextField minRoutersNumberTextField ){ this.minRoutersNumberTextField = minRoutersNumberTextField; }
	
	private JTextField maxRoutersNumberTextField;
	public JTextField getMaxRoutersNumberTextField(){ return maxRoutersNumberTextField; }
	public void setMaxRoutersNumberTextField( JTextField maxRoutersNumberTextField ){ this.maxRoutersNumberTextField = maxRoutersNumberTextField; }
	
	private JLabel switchesNumberLabel;
	public JLabel getSwitchesNumberLabel(){ return switchesNumberLabel; }
	public void setSwitchesNumberLabel( JLabel switchesNumberLabel ){ this.switchesNumberLabel = switchesNumberLabel; }

	private JTextField minSwitchesNumberTextField;
	public JTextField getMinSwitchesNumberTextField(){ return minSwitchesNumberTextField; }
	public void setMinSwitchesNumberTextField( JTextField minSwitchesNumberTextField ){ this.minSwitchesNumberTextField = minSwitchesNumberTextField; }
	
	private JTextField maxSwitchesNumberTextField;
	public JTextField getMaxSwitchesNumberTextField(){ return maxSwitchesNumberTextField; }
	public void setMaxSwitchesNumberTextField( JTextField maxSwitchesNumberTextField ){ this.maxSwitchesNumberTextField = maxSwitchesNumberTextField; }
	
	private JLabel serversNumberLabel;
	public JLabel getServersNumberLabel(){ return serversNumberLabel; }
	public void setServersNumberLabel( JLabel serversNumberLabel ){ this.serversNumberLabel = serversNumberLabel; }
	
	private JTextField minServersNumberTextField;
	public JTextField getMinServersNumberTextField(){ return minServersNumberTextField; }
	public void setMinServersNumberTextField( JTextField minServersNumberTextField ){ this.minServersNumberTextField = minServersNumberTextField; }
	
	private JTextField maxServersNumberTextField;
	public JTextField getMaxServersNumberTextField(){ return maxServersNumberTextField; }
	public void setMaxServersNumberTextField( JTextField maxServersNumberTextField ){ this.maxServersNumberTextField = maxServersNumberTextField; }
	
	private JLabel osLabel;
	public JLabel getOSlabel(){ return osLabel; }
	public void setOSlabel( JLabel osLabel ){ this.osLabel = osLabel; }
	
	private JTextField linuxPercentageTextField;
	public JTextField getLinuxPercentageTextField(){ return linuxPercentageTextField; }
	public void setLinuxPercentageTextField( JTextField linuxPercentageTextField ){ this.linuxPercentageTextField = linuxPercentageTextField; }

	private JTextField windowsPercentageTextField;
	public JTextField getWindowsPercentageTextField(){ return windowsPercentageTextField; }
	public void setWindowsPercentageTextField( JTextField windowsPercentageTextField ){ this.windowsPercentageTextField = windowsPercentageTextField; }
	
	private JTextField solarisPercentageTextField;
	public JTextField getSolarisPercentageTextField(){ return solarisPercentageTextField; }
	public void setSolarisPercentageTextField( JTextField solarisPercentageTextField ){ this.solarisPercentageTextField = solarisPercentageTextField; }

	private JTextField androidPercentageTextField;
	public JTextField getAndroidPercentageTextField(){ return androidPercentageTextField; }
	public void getAndroidPercentageTextField( JTextField androidPercentageTextField ){ this.androidPercentageTextField = androidPercentageTextField; }

	private JLabel cpuLabel;
	public JLabel getCPUlabel(){ return cpuLabel; }
	public void setCPUlabel( JLabel cpuLabel ){ this.cpuLabel = cpuLabel; }
	
	private JTextField minCPUtextField;
	public JTextField getMinCPUtextField(){ return minCPUtextField; }
	public void setMinCPUtextField( JTextField minCPUtextField ){ this.minCPUtextField = minCPUtextField; }
	
	private JTextField maxCPUtextField;
	public JTextField getMaxCPUtextField(){ return maxCPUtextField; }
	public void setMaxCPUtextField( JTextField maxCPUtextField ){ this.maxCPUtextField = maxCPUtextField; }
	
	private JLabel ramLabel;
	public JLabel getRAMlabel(){ return ramLabel; }
	public void setRAMlabel( JLabel ramLabel ){ this.ramLabel = ramLabel; }
	
	private JTextField minRAMtextField;
	public JTextField getMinRAMtextField(){ return minRAMtextField; }
	public void setMinRAMtextField( JTextField minRAMtextField ){ this.minRAMtextField = minRAMtextField; }
	
	private JTextField maxRAMtextField;
	public JTextField getMaxRAMtextField(){ return maxRAMtextField; }
	public void setMaxRAMtextField( JTextField maxRAMtextField ){ this.maxRAMtextField = maxRAMtextField; }

	private JLabel storageLabel;
	public JLabel getStorageLabel(){ return storageLabel; }
	public void setStorageLabel( JLabel storageLabel ){ this.storageLabel = storageLabel; }
	
	private JTextField minStorageTextField;
	public JTextField getMinStorageTextField(){ return minStorageTextField; }
	public void setMinStorageTextField( JTextField minStorageTextField ){ this.minStorageTextField = minStorageTextField; }
	
	private JTextField maxStorageTextField;
	public JTextField getMaxStorageTextField(){ return maxStorageTextField; }
	public void setMaxStorageTextField( JTextField maxStorageTextField ){ this.maxStorageTextField = maxStorageTextField; }
	
	private JLabel bwLabel;
	public JLabel getBWlabel(){ return bwLabel; }
	public void setBWlabel( JLabel bwLabel ){ this.bwLabel = bwLabel; }
	
	private JTextField minBWtextField;
	public JTextField getMinBWtextField(){ return minBWtextField; }
	public void setMinBWtextField( JTextField minBWtextField ){ this.minBWtextField = minBWtextField; }
    
	private JTextField maxBWtextField;
	public JTextField getMaxBWtextField(){ return maxBWtextField; }
	public void setMaxBWtextField( JTextField maxBWtextField ){ this.maxBWtextField = maxBWtextField; }

	private JLabel informationLabel;
	public JLabel getInformationLabel(){ return informationLabel; }
	public void setInformationLabel( JLabel informationLabel ){ this.informationLabel = informationLabel; }
	
	public CreateVirtualSelectPanel()
    {   
    	this.setLayout( new java.awt.BorderLayout() );
        this.add( this.titlePanel(), BorderLayout.NORTH );
        this.add( this.contentPanel(), BorderLayout.CENTER );
    }
	private JPanel titlePanel()
	{
        JLabel titleLabel = new JLabel( "Random virtual networks" );
        titleLabel.setFont( new Font( "MS Sans Serif", Font.BOLD, 14 ) );
        titleLabel.setBorder( new EmptyBorder( new Insets( 10, 10, 10, 10 ) ) );
        titleLabel.setOpaque( true );
        
        JPanel titlePanel = new JPanel();
        titlePanel.setLayout( new java.awt.BorderLayout() );
        titlePanel.setBackground( Color.gray );
        titlePanel.add( titleLabel, BorderLayout.CENTER );
        titlePanel.add( new JSeparator(), BorderLayout.SOUTH );
        
        return titlePanel;
	}
	private JPanel contentPanel()
	{
		JPanel informationPanel = this.informationPanel();
		JPanel networksPanel = this.networksPanel();
		JPanel nodesPanel = this.nodesPanel();
		JPanel nodePanel  = this.nodePanel();
		JPanel linkPanel  = this.linkPanel();
		
        JPanel contentPanel = new JPanel();
        
		GroupLayout groupLayout = new GroupLayout( contentPanel );
		groupLayout.setAutoCreateGaps( true );
		groupLayout.setAutoCreateContainerGaps( true );
		groupLayout.setHorizontalGroup( groupLayout.createSequentialGroup().addGroup( groupLayout.createParallelGroup().addComponent( informationPanel ).addComponent( networksPanel ).addComponent( nodesPanel ).addComponent( nodePanel ).addComponent( linkPanel ) ) );
		groupLayout.setVerticalGroup( groupLayout.createParallelGroup().addGroup( groupLayout.createSequentialGroup().addComponent( informationPanel ).addComponent( networksPanel ).addComponent( nodesPanel ).addComponent( nodePanel ).addComponent( linkPanel ) ) );
		contentPanel.setLayout( groupLayout );
        
        return contentPanel;
	}
	
    private JPanel informationPanel()
	{
		this.setInformationLabel( new JLabel() );
		
		JPanel informationPanel = new JPanel();
		informationPanel.add( this.getInformationLabel() );
		
		return informationPanel;
	}
	
	private JPanel networksPanel()
	{
    	TitledBorder titledBorder = BorderFactory.createTitledBorder( BorderFactory.createLineBorder( Color.black ), "<html><b>VIRTUAL NETWORKS</b></html>" );
        titledBorder.setTitleJustification( TitledBorder.CENTER );
        
        JPanel networksPanel = new JPanel();
        networksPanel.setLayout( new GridLayout( 0, 1 ) );
        networksPanel.setBorder( titledBorder );
        networksPanel.add( this.networksNumberPanel() );
        networksPanel.add( this.windowTimeUnitsNumberPanel() );
        networksPanel.add( this.poissonArrivesPanel() );
        networksPanel.add( this.exponentialLifetimePanel() );
         
        return networksPanel;
	}
    private JPanel networksNumberPanel()
    {
    	this.setNetworksNumberLabel( new JLabel( "<html><b>Networks number:</b></html>" ) );
    	this.setNetworksNumberTextField( new JTextField( Integer.toString( VirtualNetworks.NETWORKS_NUMBER ) ) );
    	this.getNetworksNumberTextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getNetworksNumberTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel networksNumberPanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
        networksNumberPanel.add( this.getNetworksNumberLabel() );
        networksNumberPanel.add( this.getNetworksNumberTextField() );
        
        return networksNumberPanel;
    }
    private JPanel windowTimeUnitsNumberPanel()
    {
    	this.setWindowTimeUnitsNumberLabel( new JLabel( "<html><b>Window time units number:</b></html>" ) );
    	
    	this.setWindowTimeUnitsNumberTextField( new JTextField( Integer.toString( VirtualNetworks.WINDOW_TIME_UNITS_NUMBER ) ) );
    	this.getWindowTimeUnitsNumberTextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getWindowTimeUnitsNumberTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel windowTimeUnitsNumberPanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
        windowTimeUnitsNumberPanel.add( this.getWindowTimeUnitsNumberLabel() );
        windowTimeUnitsNumberPanel.add( this.getWindowTimeUnitsNumberTextField() );
        
        return windowTimeUnitsNumberPanel;
    }
    private JPanel poissonArrivesPanel()
    {
    	this.setPoissonArrivesLabel( new JLabel( "<html><b>Networks number per window in Poisson arrives:</b></html>" ) );
    	
    	this.setPoissonArrivesTextField( new JTextField( Integer.toString( (int) VirtualNetworks.POISSON_ARRIVES ) ) );
    	this.getPoissonArrivesTextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getPoissonArrivesTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel poissonArrivesPanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
        poissonArrivesPanel.add( this.getPoissonArrivesLabel() );
        poissonArrivesPanel.add( this.getPoissonArrivesTextField() );
                
        return poissonArrivesPanel;
    }
    private JPanel exponentialLifetimePanel()
    {
    	this.setExponentialLifetimeLabel( new JLabel( "<html><b>Average time units of exponential lifetime:</b></html>" ) );
    	
    	this.setExponentialLifetimeTextField( new JTextField( Integer.toString( (int) VirtualNetworks.EXPONENTIAL_LIFETIME ) ) );
    	this.getExponentialLifetimeTextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getExponentialLifetimeTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel exponentialLifetimePanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
        exponentialLifetimePanel.add( this.getExponentialLifetimeLabel() );
        exponentialLifetimePanel.add( this.getExponentialLifetimeTextField() );
        
        return exponentialLifetimePanel;
    }
    
    private JPanel nodesPanel()
	{
    	TitledBorder titledBorder = BorderFactory.createTitledBorder( BorderFactory.createLineBorder( Color.black ), "<html><b>SDN NODES</b></html>" );
        titledBorder.setTitleJustification( TitledBorder.CENTER );
        
        JPanel nodesPanel = new JPanel();
        nodesPanel.setLayout( new GridLayout( 0, 1 ) );
        nodesPanel.setBorder( titledBorder );
        nodesPanel.add( this.routersNumberRangePanel() );
        nodesPanel.add( this.switchesNumberRangePanel() );
        nodesPanel.add( this.serversNumberRangePanel() );
        nodesPanel.add( this.osPercentagesPanel() );
        
        return nodesPanel;
	}
    private JPanel routersNumberRangePanel()
    {
    	this.setRoutersNumberLabel( new JLabel( "<html><b>Routers number:</b></html>" ) );
    	
    	this.setMinRoutersNumberTextField( new JTextField( Integer.toString( VirtualNetworks.MIN_ROUTERS_NUMBER ) ) );
        this.getMinRoutersNumberTextField().setPreferredSize( new Dimension( 25, 20 ) );
        this.getMinRoutersNumberTextField().setHorizontalAlignment( JTextField.CENTER );
    	
        this.setMaxRoutersNumberTextField( new JTextField( Integer.toString( VirtualNetworks.MAX_ROUTERS_NUMBER ) ) );
        this.getMaxRoutersNumberTextField().setPreferredSize( new Dimension( 25, 20 ) );
        this.getMaxRoutersNumberTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel routersNumberRangePanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
    	routersNumberRangePanel.add( this.getRoutersNumberLabel() );
    	routersNumberRangePanel.add( new JLabel( "Between" ) );
    	routersNumberRangePanel.add( this.getMinRoutersNumberTextField() );
        routersNumberRangePanel.add( new JLabel( "and" ) );
        routersNumberRangePanel.add( this.getMaxRoutersNumberTextField() );
        
        return routersNumberRangePanel;
    }
    private JPanel switchesNumberRangePanel()
    {
    	this.setSwitchesNumberLabel( new JLabel( "<html><b>Switches number:</b></html>" ) );
    	
    	this.setMinSwitchesNumberTextField( new JTextField( Integer.toString( VirtualNetworks.MIN_SWITCHES_NUMBER ) ) );
        this.getMinSwitchesNumberTextField().setPreferredSize( new Dimension( 25, 20 ) );
        this.getMinSwitchesNumberTextField().setHorizontalAlignment( JTextField.CENTER );
    	
        this.setMaxSwitchesNumberTextField( new JTextField( Integer.toString( VirtualNetworks.MAX_SWITCHES_NUMBER ) ) );
        this.getMaxSwitchesNumberTextField().setPreferredSize( new Dimension( 25, 20 ) );
        this.getMaxSwitchesNumberTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel switchesNumberRangePanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
    	switchesNumberRangePanel.add( this.getSwitchesNumberLabel() );
    	switchesNumberRangePanel.add( new JLabel( "Between" ) );
    	switchesNumberRangePanel.add( this.getMinSwitchesNumberTextField() );
        switchesNumberRangePanel.add( new JLabel( "and" ) );
        switchesNumberRangePanel.add( this.getMaxSwitchesNumberTextField() );
        
        return switchesNumberRangePanel;
    }
    private JPanel serversNumberRangePanel()
    {
    	this.setServersNumberLabel( new JLabel( "<html><b>Servers number:</b></html>" ) );
    	
    	this.setMinServersNumberTextField( new JTextField( Integer.toString( VirtualNetworks.MIN_SERVERS_NUMBER ) ) );
        this.getMinServersNumberTextField().setPreferredSize( new Dimension( 25, 20 ) );
        this.getMinServersNumberTextField().setHorizontalAlignment( JTextField.CENTER );
    	
        this.setMaxServersNumberTextField( new JTextField( Integer.toString( VirtualNetworks.MAX_SERVERS_NUMBER ) ) );
        this.getMaxServersNumberTextField().setPreferredSize( new Dimension( 25, 20 ) );
        this.getMaxServersNumberTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel serversNumberRangePanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
    	serversNumberRangePanel.add( this.getServersNumberLabel() );
    	serversNumberRangePanel.add( new JLabel( "Between" ) );
    	serversNumberRangePanel.add( this.getMinServersNumberTextField() );
        serversNumberRangePanel.add( new JLabel( "and" ) );
        serversNumberRangePanel.add( this.getMaxServersNumberTextField() );
        
        return serversNumberRangePanel;
    }
    private JPanel osPercentagesPanel()
    {
    	this.setOSlabel( new JLabel( "<html><b>Operating systems %:</b></html>" ) );
    	    	
    	this.setLinuxPercentageTextField( new JTextField( Integer.toString( VirtualNetworks.LINUX_PERCENTAGE ) ) );
    	this.getLinuxPercentageTextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getLinuxPercentageTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	this.setWindowsPercentageTextField( new JTextField( Integer.toString( VirtualNetworks.WINDOWS_PERCENTAGE ) ) );
    	this.getWindowsPercentageTextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getWindowsPercentageTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	this.setSolarisPercentageTextField( new JTextField( Integer.toString( VirtualNetworks.SOLARIS_PERCENTAGE ) ) );
    	this.getSolarisPercentageTextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getSolarisPercentageTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	this.getAndroidPercentageTextField( new JTextField( Integer.toString( VirtualNetworks.ANDROID_PERCENTAGE ) ) );
    	this.getAndroidPercentageTextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getAndroidPercentageTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel osPercentagePanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
    	
    	osPercentagePanel.add( this.getOSlabel() );
    	
    	osPercentagePanel.add( new JLabel( "Linux:" ) );
    	osPercentagePanel.add( this.getLinuxPercentageTextField() );
    	
    	osPercentagePanel.add( new JLabel( "Windows:" ) );
    	osPercentagePanel.add( this.getWindowsPercentageTextField() );
    	
    	osPercentagePanel.add( new JLabel( "Solaris:" ) );
    	osPercentagePanel.add( this.getSolarisPercentageTextField() );
    	
    	osPercentagePanel.add( new JLabel( "Android:" ) );
    	osPercentagePanel.add( this.getAndroidPercentageTextField() );
    	
    	return osPercentagePanel;
    }
    
    private JPanel nodePanel()
	{
    	TitledBorder titledBorder = BorderFactory.createTitledBorder( BorderFactory.createLineBorder( Color.black ), "<html><b>SDN NODE</b></html>" );
        titledBorder.setTitleJustification( TitledBorder.CENTER );
        
        JPanel nodePanel = new JPanel();
        nodePanel.setLayout( new GridLayout( 0, 1 ) );
        nodePanel.setBorder( titledBorder );
        nodePanel.add( this.cpuPanel() );
        nodePanel.add( this.ramPanel() );
        nodePanel.add( this.storagePanel() );
                
        return nodePanel;
	}
    private JPanel cpuPanel()
    {
    	this.setCPUlabel( new JLabel( "<html><b>CPU:</b></html>" ) );
    	this.setMinCPUtextField( new JTextField( Integer.toString( VirtualNetworks.MIN_CPU ) ) );
    	this.getMinCPUtextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getMinCPUtextField().setHorizontalAlignment( JTextField.CENTER );    	
    	this.setMaxCPUtextField( new JTextField( Integer.toString( VirtualNetworks.MAX_CPU ) ) );
    	this.getMaxCPUtextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getMaxCPUtextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel cpuPanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
    	cpuPanel.add( this.getCPUlabel() );
    	cpuPanel.add( new JLabel( "Between" ) );
    	cpuPanel.add( this.getMinCPUtextField() );
    	cpuPanel.add( new JLabel( "and" ) );
    	cpuPanel.add( this.getMaxCPUtextField() );
    	
    	return cpuPanel;
    }
    private JPanel ramPanel()
    {
    	this.setRAMlabel( new JLabel( "<html><b>RAM:</b></html>" ) );
    	this.setMinRAMtextField( new JTextField( Integer.toString( VirtualNetworks.MIN_RAM ) ) );
    	this.getMinRAMtextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getMinRAMtextField().setHorizontalAlignment( JTextField.CENTER );
    	this.setMaxRAMtextField( new JTextField( Integer.toString( VirtualNetworks.MAX_RAM ) ) );
    	this.getMaxRAMtextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getMaxRAMtextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel ramPanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
    	ramPanel.add( this.getRAMlabel() );
    	ramPanel.add( new JLabel( "Between" ) );
    	ramPanel.add( this.getMinRAMtextField() );
    	ramPanel.add( new JLabel( "and" ) );
    	ramPanel.add( this.getMaxRAMtextField() );
    	
        return ramPanel;
    }
    private JPanel storagePanel()
    {
    	this.setStorageLabel( new JLabel( "<html><b>Storage:</b></html>" ) );
    	this.setMinStorageTextField( new JTextField( Integer.toString( VirtualNetworks.MIN_STORAGE ) ) );
    	this.getMinStorageTextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getMinStorageTextField().setHorizontalAlignment( JTextField.CENTER );
    	this.setMaxStorageTextField( new JTextField( Integer.toString( VirtualNetworks.MAX_STORAGE ) ) );
    	this.getMaxStorageTextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getMaxStorageTextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel storagePanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
    	storagePanel.add( this.getStorageLabel() );
    	storagePanel.add( new JLabel( "Between" ) );
    	storagePanel.add( this.getMinStorageTextField() );
    	storagePanel.add( new JLabel( "and" ) );
    	storagePanel.add( this.getMaxStorageTextField() );
    	
    	return storagePanel;
    }
        
    private JPanel linkPanel()
	{
    	TitledBorder titledBorder = BorderFactory.createTitledBorder( BorderFactory.createLineBorder( Color.black ), "<html><b>SDN LINK</b></html>" );
        titledBorder.setTitleJustification( TitledBorder.CENTER );
        
        JPanel linkPanel = new JPanel();
        linkPanel.setLayout( new GridLayout( 0, 1 ) );
        linkPanel.setBorder( titledBorder );
        linkPanel.add( this.bwPanel() );
                
        return linkPanel;
	}
    private JPanel bwPanel()
    {
    	this.setBWlabel( new JLabel( "<html><b>Bandwidth:</b></html>" ) );
    	
    	this.setMinBWtextField( new JTextField( Integer.toString( VirtualNetworks.MIN_BW ) ) );
    	this.getMinBWtextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getMinBWtextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	this.setMaxBWtextField( new JTextField( Integer.toString( VirtualNetworks.MAX_BW ) ) );
    	this.getMaxBWtextField().setPreferredSize( new Dimension( 25, 20 ) );
    	this.getMinBWtextField().setHorizontalAlignment( JTextField.CENTER );
    	
    	JPanel bwPanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
        bwPanel.add( this.getBWlabel() );
        bwPanel.add( new JLabel( "Between" ) );
        bwPanel.add( this.getMinBWtextField() );
        bwPanel.add( new JLabel( "and" ) );
        bwPanel.add( this.getMaxBWtextField() );
        
        return bwPanel;
    }
    
	public void addListeners( DocumentListener documentListener, ActionListener actionListener )
	{
		this.getNetworksNumberTextField().getDocument().addDocumentListener( documentListener );
		this.getWindowTimeUnitsNumberTextField().getDocument().addDocumentListener( documentListener );
		this.getPoissonArrivesTextField().getDocument().addDocumentListener( documentListener );
		this.getExponentialLifetimeTextField().getDocument().addDocumentListener( documentListener );
		
		this.getMinRoutersNumberTextField().getDocument().addDocumentListener( documentListener );
		this.getMaxRoutersNumberTextField().getDocument().addDocumentListener( documentListener );
		
		this.getMinSwitchesNumberTextField().getDocument().addDocumentListener( documentListener );
		this.getMaxSwitchesNumberTextField().getDocument().addDocumentListener( documentListener );
		
		this.getMinServersNumberTextField().getDocument().addDocumentListener( documentListener );
		this.getMaxServersNumberTextField().getDocument().addDocumentListener( documentListener );
		
		this.getLinuxPercentageTextField().getDocument().addDocumentListener( documentListener );
		this.getWindowsPercentageTextField().getDocument().addDocumentListener( documentListener );
		this.getSolarisPercentageTextField().getDocument().addDocumentListener( documentListener );
		this.getAndroidPercentageTextField().getDocument().addDocumentListener( documentListener );
		
		this.getMinCPUtextField().getDocument().addDocumentListener( documentListener );
		this.getMaxCPUtextField().getDocument().addDocumentListener( documentListener );
		
		this.getMinRAMtextField().getDocument().addDocumentListener( documentListener );
		this.getMaxRAMtextField().getDocument().addDocumentListener( documentListener );
		
		this.getMinStorageTextField().getDocument().addDocumentListener( documentListener );
		this.getMaxStorageTextField().getDocument().addDocumentListener( documentListener );
		
		this.getMinBWtextField().getDocument().addDocumentListener( documentListener );
		this.getMaxBWtextField().getDocument().addDocumentListener( documentListener );
	}
	
	public boolean check()
	{
		this.getInformationLabel().setText( "Press \"Next\" to create random virtual networks" );
		this.getInformationLabel().setForeground( Color.BLACK );
		
		if(      !this.checkNetworksNumber() )			return false;
		else if( !this.checkWindowTimeUnitsNumber() )	return false;
		else if( !this.checkPoissonArrives() )			return false;
		else if( !this.checkExponentialLifetime() )		return false;
		
		else if( !this.checkRoutersNumber() )			return false;
		else if( !this.checkSwitchesNumber() )			return false;
		else if( !this.checkServersNumber() )			return false;
		else if( !this.checkOSpercentages() )			return false;
		
		else if( !this.checkCPU() )						return false;
		else if( !this.checkRAM() )						return false;
		else if( !this.checkStorage() )					return false;
		
		else if( !this.checkBW() )						return false;
		
		else 											return true;
	}
	
	private boolean checkNetworksNumber()
	{
		int lowestNetworksNumber = 1;
		int highestNetworksNumber = 50;
		
		try
		{
			int networksNumber = Integer.parseInt( this.getNetworksNumberTextField().getText() );
			
			if( !( lowestNetworksNumber <= networksNumber && networksNumber <= highestNetworksNumber ) )
				throw new NumberFormatException();
			
			this.getNetworksNumberLabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>A value between " + lowestNetworksNumber + " and " + highestNetworksNumber + "</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getNetworksNumberLabel().setForeground( Color.RED );
			
			return false;
		}
	}
	private boolean checkWindowTimeUnitsNumber()
	{	
		int lowestWindowTimeUnitsNumber = 1;
		int highestWindowTimeUnitsNumber = 50;
		
		try
		{
			int windowTimeUnitsNumber = Integer.parseInt( this.getWindowTimeUnitsNumberTextField().getText() );
			
			if( !( lowestWindowTimeUnitsNumber <= windowTimeUnitsNumber && windowTimeUnitsNumber <= highestWindowTimeUnitsNumber ) )
				throw new NumberFormatException();
			
			this.getWindowTimeUnitsNumberLabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>A value between " + lowestWindowTimeUnitsNumber + " and " + highestWindowTimeUnitsNumber + "</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getWindowTimeUnitsNumberLabel().setForeground( Color.RED );
			
			return false;
		}
	}
	private boolean checkPoissonArrives()
	{
		int lowestPoissonArrives = 1;
		int highestPoissonArrives = 50;
		
		try
		{
			double poissonArrives = Double.parseDouble( this.getPoissonArrivesTextField().getText() );
			
			if( !( lowestPoissonArrives <= poissonArrives && poissonArrives <= highestPoissonArrives ) )
				throw new NumberFormatException();
			
			this.getPoissonArrivesLabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>A value between " + lowestPoissonArrives + " and " + highestPoissonArrives + "</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getPoissonArrivesLabel().setForeground( Color.RED );
			
			return false;
		}
	}
	private boolean checkExponentialLifetime()
	{
		int lowestExponentialLifetime = 1;
		int highestExponentialLifetime = 50;
		
		try
		{
			double exponentialLifetime = Double.parseDouble( this.getExponentialLifetimeTextField().getText() );
			
			if( !( lowestExponentialLifetime <= exponentialLifetime && exponentialLifetime <= highestExponentialLifetime ) )
				throw new NumberFormatException();
			
			this.getExponentialLifetimeLabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>A value between " + lowestExponentialLifetime + " and " + highestExponentialLifetime + "</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getExponentialLifetimeLabel().setForeground( Color.RED );
			
			return false;
		}
	}
	
	private boolean checkRoutersNumber()
	{
		int lowestMinRoutersNumber = 1;
		int highestMaxRoutersNumber = 50;
		
		try
		{
			int minRoutersNumber = Integer.parseInt( this.getMinRoutersNumberTextField().getText() );
			int maxRoutersNumber  = Integer.parseInt( this.getMaxRoutersNumberTextField().getText() );
			
			if( !( lowestMinRoutersNumber <= minRoutersNumber && minRoutersNumber <= maxRoutersNumber && maxRoutersNumber <= highestMaxRoutersNumber ) )
				throw new NumberFormatException();
			
			this.getRoutersNumberLabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>Minimum value " + lowestMinRoutersNumber + " and maximum value " + highestMaxRoutersNumber + "</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getRoutersNumberLabel().setForeground( Color.RED );
			
			return false;
		}
	}
	private boolean checkSwitchesNumber()
	{
		int lowestMinSwitchesNumber = 1;
		int highestMaxSwitchesNumber = 50;
		
		try
		{
			int minSwitchesNumber = Integer.parseInt( this.getMinSwitchesNumberTextField().getText() );
			int maxSwitchesNumber  = Integer.parseInt( this.getMaxSwitchesNumberTextField().getText() );
			
			if( !( lowestMinSwitchesNumber <= minSwitchesNumber && minSwitchesNumber <= maxSwitchesNumber && maxSwitchesNumber <= highestMaxSwitchesNumber ) )
				throw new NumberFormatException();
			
			this.getSwitchesNumberLabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>Minimum value " + lowestMinSwitchesNumber + " and maximum value " + highestMaxSwitchesNumber + "</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getSwitchesNumberLabel().setForeground( Color.RED );
			
			return false;
		}
	}
	private boolean checkServersNumber()
	{
		int lowestMinServersNumber = 1;
		int highestMaxServersNumber = 50;
		
		try
		{
			int minServersNumber = Integer.parseInt( this.getMinServersNumberTextField().getText() );
			int maxServersNumber  = Integer.parseInt( this.getMaxServersNumberTextField().getText() );
			
			if( !( lowestMinServersNumber <= minServersNumber && minServersNumber <= maxServersNumber && maxServersNumber <= highestMaxServersNumber ) )
				throw new NumberFormatException();
			
			this.getServersNumberLabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>Minimum value " + lowestMinServersNumber + " and maximum value " + highestMaxServersNumber + "</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getServersNumberLabel().setForeground( Color.RED );
			
			return false;
		}
	}
    private boolean checkOSpercentages()
	{
		try
		{
			int linuxPercentage   = Integer.parseInt( this.getLinuxPercentageTextField().getText() );
			int windowsPercentage = Integer.parseInt( this.getWindowsPercentageTextField().getText() );
			int solarisPercentage = Integer.parseInt( this.getSolarisPercentageTextField().getText() );
			int androidPercentage = Integer.parseInt( this.getAndroidPercentageTextField().getText() );
								
			if( !( 0 <= linuxPercentage   && linuxPercentage   <= 100 ) || 
				!( 0 <= windowsPercentage && windowsPercentage <= 100 ) || 
				!( 0 <= solarisPercentage && solarisPercentage <= 100 ) || 
				!( 0 <= androidPercentage && androidPercentage <= 100 ) || 
				!( linuxPercentage + windowsPercentage + solarisPercentage + androidPercentage == 100 ) )
				throw new NumberFormatException();
			
			this.getOSlabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>Operating systems of nodes must sum to 100</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getOSlabel().setForeground( Color.RED );
			
			return false;
		}
	}
    
    private boolean checkCPU()
    {
    	int lowestMinCPU = 0;
    	int highestMaxCPU = 100;
    	
		try
		{
			int minCPU = Integer.parseInt( this.getMinCPUtextField().getText() );
			int maxCPU = Integer.parseInt( this.getMaxCPUtextField().getText() );
			
			if( !( lowestMinCPU <= minCPU && minCPU <= maxCPU && maxCPU <= highestMaxCPU ) )
				throw new NumberFormatException();
			
			this.getCPUlabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>Minimum value " + lowestMinCPU + " and maximum value " + highestMaxCPU + "</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getCPUlabel().setForeground( Color.RED );
			
			return false;
		}
    }
    private boolean checkRAM()
    {
    	int lowestMinRAM = 0;
    	int highestMaxRAM = 100;
    	
		try
		{
			int minRAM = Integer.parseInt( this.getMinRAMtextField().getText() );
			int maxRAM = Integer.parseInt( this.getMaxRAMtextField().getText() );
			
			if( !( lowestMinRAM <= minRAM && minRAM <= maxRAM && maxRAM <= 100 ) )
				throw new NumberFormatException();
			
			this.getRAMlabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>Minimum value " + lowestMinRAM + " and maximum value " + highestMaxRAM + "</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getRAMlabel().setForeground( Color.RED );
			
			return false;
		}
    }
    private boolean checkStorage()
    {
    	int lowestMinStorage = 0;
    	int highestMaxStorage = 100;
    	
		try
		{
			int minStorage = Integer.parseInt( this.getMinStorageTextField().getText() );
			int maxStorage = Integer.parseInt( this.getMaxStorageTextField().getText() );
			
			if( !( lowestMinStorage <= minStorage && minStorage <= maxStorage && maxStorage <= highestMaxStorage ) )
				throw new NumberFormatException();
			
			this.getStorageLabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>Minimum value " + lowestMinStorage + " and maximum value " + highestMaxStorage + "</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getStorageLabel().setForeground( Color.RED );
			
			return false;
		}
    }
    
    private boolean checkBW()
    {
    	int lowestMinBW = 0;
    	int highestMaxBW = 100;
    	
		try
		{
			int minBW = Integer.parseInt( this.getMinBWtextField().getText() );
			int maxBW = Integer.parseInt( this.getMaxBWtextField().getText() );
			
			if( !( lowestMinBW <= minBW && minBW <= maxBW && maxBW <= highestMaxBW ) )
				throw new NumberFormatException();
			
			this.getBWlabel().setForeground( Color.BLACK );
			
			return true;
		}
		catch( NumberFormatException numberFormatException )
		{
			this.getInformationLabel().setText( "<html><b>Minimum value " + lowestMinBW + " and maximum value " + highestMaxBW + "</b></html>" );
			this.getInformationLabel().setForeground( Color.RED );
			
			this.getBWlabel().setForeground( Color.RED );
			
			return false;
		}
    }
	
}
